home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / obsolete / runs_test.pro < prev    next >
Text File  |  1997-07-08  |  3KB  |  113 lines

  1. ; $Id: runs_test.pro,v 1.2 1997/01/15 04:02:19 ali Exp $
  2. ;
  3. ;  Copyright (c) 1993-1997, Research Systems Inc.  All rights
  4. ;  reserved. Unauthorized reproduction prohibited.
  5.  
  6. pro runs_test, Sequence1, RunNo, Prob,BinNo,Z,  $
  7.      List_Name = Ln
  8. ;+ 
  9. ; NAME:
  10. ;    RUNS_TEST
  11. ;
  12. ; PURPOSE:
  13. ;    To test for nonrandomness in a sequence of 0 and 1's by
  14. ;    counting the number of runs and computing its probabilty.
  15. ;
  16. ; CATEGORY:
  17. ;    Statistics.
  18. ;
  19. ; CALLING SEQUENCE:
  20. ;    RUNS_TEST, Sequence1, RunNo, Prob, BinNo, Z, LIST_NAME = Ln
  21. ;
  22. ; INPUTS:
  23. ;    Sequence1:    The vector of 0's and 1's.
  24. ;           
  25. ; OPTIONAL OUTPUT PARAMETERS:
  26. ;    RunNo:    Total number of rums.
  27. ;                            
  28. ;    Prob:    probabilty of total number of runs, if number of 0's and 
  29. ;        number of 1's both exceeds 10.Otherwise, undefined and -1 is
  30. ;        returned in Prob.
  31. ;
  32. ;    BinNo:    [ number of 0's, number of 1's]
  33. ;
  34. ;    Z:    Approximately normal test statistic computed when number \
  35. ;        of 0' and number of 1's both exceed 10.
  36. ;                                                           
  37. ; RESTRICTIONS:
  38. ;    None.
  39. ;
  40. ; COMMON BLOCKS:
  41. ;    None.
  42. ;
  43. ; PROCEDURE:
  44. ;    If either the number of 0's or the number of 1's does not exceed 10,
  45. ;    then the probability must be looked up in a table. Otherwise, it is
  46. ;    estimated with the normal distribution. Any nonbinary values are 
  47. ;    removed from the sequence.
  48. ;-
  49.  
  50.  
  51.  
  52. On_Error,2
  53.  
  54. if N_ELEMENTS(sequence1) eq 0 THEN BEGIN
  55.    print, "runs_test- Sequence is undefined."
  56.    goto,done
  57. ENDIF
  58.  
  59. sequence = sequence1
  60. temp = where( Sequence EQ  0 OR Sequence EQ 1,countNB)
  61.  
  62.  
  63. if (countNB NE 0) THEN BEGIN
  64.      Seq = Sequence
  65.      Sequence = Sequence(temp)             ;remove nonbinaries
  66. ENDIF ELSE BEGIN
  67.       print, " runs_test-Too many missing data values."
  68.       goto,done
  69. ENDELSE
  70.  
  71. SD= size(Sequence)
  72.  
  73.  
  74.  
  75. C=SD(1)
  76.  
  77. h0 = where( Sequence EQ 0,y0)         ;count 0's and runs of 0
  78.  
  79. if y0 ne 0 then $
  80.  temp = where(H0 + 1 NE Shift(h0,-1),n0) $
  81. else n0 = 0
  82.  
  83. y1 = SD(1) - y0                       ;count 1's and runs of 1
  84.  
  85. if(Sequence(SD(1)-1) NE Sequence(0)) THEN $
  86.    n1 = n0      $
  87. ELSE if Sequence(0) EQ 1 then n1 = n0 + 1 $
  88. ELSE n1 = n0-1
  89.  
  90. R = n0 + n1
  91. RunNo=R
  92. BinNo = [y0,y1]
  93.  
  94. if y0 eq 0 or y1 eq 0 THEN BEGIN
  95.    Prob = 0
  96.    Z    = 1.e12
  97.    print, 'runs_test- all sequence values are the same'
  98.    goto, DONE
  99. ENDIF
  100.  
  101.  
  102. E = 2.0*y0*y1/(y0 + y1) + 1.0
  103. V = 2.0*y0*y1*(2.0*y1*y0 - y0 -y1)/        $
  104.               ((y0 + y1 -1.0)*(y1+y0)^2)
  105. Z = (R-E)/sqrt(V)
  106. if (y0 LE 10 or y1 LE 10) THEN $
  107.    Prob = -1 $
  108. else Prob =1- gaussint(abs(Z))                   
  109.  
  110. DONE:
  111. RETURN
  112. END
  113.